﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Frogism.Core;
using Frogism.Domain;
using NUnit.Framework;
namespace Frogism.Tests.Reporting
{
    [TestFixture]
    public class YearBudgetBuilderTests
    {
        IList<IAccount> accounts;
        DateTime current;
        YearBugetBuilder builder;
        [SetUp]
        public void Setup()
        {
             accounts = new List<IAccount>();
             current = new DateTime(2010, 1, 14, 0, 0, 0);
             builder = new YearBugetBuilder(current);
        }
        [Test]
        public void SetupWeeks(){
    
            var weekItems = builder.GetYearSoFar( accounts);
            Assert.IsNotNull(weekItems);
            Assert.AreEqual(3, weekItems.Count(), "Count");
            Assert.AreEqual(1, weekItems.First().StartDate.Day, "first start day");
            Assert.AreEqual(current.Day, weekItems.Last().EndDate.Day, "last end date");
        }
        [Test]
        public void WeekGetsBudget()
        {
           // var a = new Account();
           // a.AccountType = DBConst.AccountTypeChecking;
           // a.Transactions.Add(new Transaction() { AccountId = 1, IsConfirmed = true, Amount = 33, TransactionDate = new DateTime(2010, 1, 12), TransactionType = TransactionType.Expense });
            var weekItems = builder.GetYearSoFar( accounts);
            Assert.AreEqual(50*2,weekItems.First().Balance,"first");
            Assert.AreEqual(50 * 7, weekItems.ElementAt(1).Balance,"second");
            Assert.AreEqual(50*5, weekItems.Last().Balance,"last");
        }
        [Test]
        public void LastPartialWeekBalance()
        {
            var a = new Account();
            a.AccountType = DBConst.AccountTypeChecking;
            a.Transactions.Add(new Transaction() { AccountId = 1, IsConfirmed = true, Amount = 33, TransactionDate = new DateTime(2010, 1, 12), TransactionType = TransactionType.Expense });
            accounts.Add(a);
            var weekItems = builder.GetYearSoFar( accounts);
            Assert.AreEqual(50*2,weekItems.First().Balance);
            Assert.AreEqual(50*5-33, weekItems.Last().Balance);
        }
        [Test]
        public void MidWeekBalance()
        {
            var a = new Account();
            a.AccountType = DBConst.AccountTypeChecking;
            a.Transactions.Add(new Transaction() { AccountId = 1, IsConfirmed = true, Amount = 33, TransactionDate = new DateTime(2010, 1, 7), TransactionType = TransactionType.Expense });
            accounts.Add(a);
            var weekItems = builder.GetYearSoFar(accounts);
            Assert.AreEqual(50 * 2, weekItems.First().Balance);
            Assert.AreEqual(50 * 7-33, weekItems.ElementAt(1).Balance);

            Assert.AreEqual(50 * 5, weekItems.Last().Balance);
        }
        [Test]
        public void GetFirstWeeksBalance()
        {
            var a = new Account();
            a.AccountType = DBConst.AccountTypeChecking;
            a.Transactions.Add(new Transaction() { AccountId = 1, IsConfirmed = true, Amount = 33, TransactionDate = new DateTime(2010, 1, 2), TransactionType = TransactionType.Expense });
            accounts.Add(a);
            var weekItems = builder.GetYearSoFar( accounts);
            Assert.AreEqual(50 * 2 - 33, weekItems.First().Balance);
            Assert.AreEqual(50 * 5, weekItems.Last().Balance);
        }
    }
}
